﻿Public Class frmTraCuuTheoDiaDiem

    Private Sub btnTHOAT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTHOAT.Click
        Me.Close()
    End Sub

    Private Sub btnTIM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTIM.Click
        Dim _maPhong As Integer = cboMAPHONG.SelectedValue
        Dim _maLop As Integer = cboMALOP.SelectedValue

        Dim _strWhere As String = String.Empty

        If _maPhong <> 0 Then
            _strWhere += " PH.MaPhong like " & _maPhong
        End If

        If _maLop <> 0 Then
            If Not String.IsNullOrEmpty(_strWhere) Then
                _strWhere += " and "
            End If
            _strWhere += " LH.MaLop like " & _maLop
        End If

        'If Not String.IsNullOrEmpty(_maCM) Then
        '    _strWhere += " CM.MaChuyenMon like " & _maCM
        'End If

        If Not String.IsNullOrEmpty(_strWhere) Then
            _strWhere = " and " & _strWhere
        End If

        Dim strSQL As String = "select GV.MaGV, GV.HoTen, PH.TenPhong, LH.TenLop, CM.TenChuyenMon from GIAOVIEN GV, LOPHOC LH, PHONGHOC PH, PHANCONG PC, CHUYENMON CM where GV.MaChuyenMon=CM.MaChuyenMon and GV.MaGV=PC.MaGV and PH.MaPhong=PC.MaPhong and PC.MaLop=LH.MaLop" & _strWhere
        Dim _tc As DataTable
        _tc = PhanCongDAO.SelectByGV(strSQL)
        dgvTCTheoDD.DataSource = _tc
    End Sub

    Private Sub frmTraCuuTheoDiaDiem_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim _ph As New DataTable
        _ph = PhongHocDAO.SelectAll()
        cboMAPHONG.DataSource = _ph
        cboMAPHONG.DisplayMember = "TenPhong"
        cboMAPHONG.ValueMember = "MaPhong"
        cboMAPHONG.SelectedIndex = -1

        Dim _lh As New DataTable
        _lh = LopHocDAO.SelectAll()
        cboMALOP.DataSource = _lh
        cboMALOP.DisplayMember = "TenLop"
        cboMALOP.ValueMember = "MaLop"
        cboMALOP.SelectedIndex = -1
    End Sub

    Private Sub btnIN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIN.Click
        Dim _dt As New DataTable
        _dt.Clear()
        _dt = PhanCongDAO.SelectAll()
        dgvTCTheoDD.DataSource = _dt
        'Nap du lieu cho Report
        Dim myReport As New CR_TraCuuDD()
        myReport.SetDataSource(_dt.DataSet)
        'Nap form in report
        Dim f As New InTraCuuDD
        f.CRV_TraCuuDD.ReportSource = myReport
        f.ShowDialog()
    End Sub
End Class